package com.rd.student.dashuju.zhengchengxiang.July13th.Test;

import java.util.LinkedList;
import java.util.Scanner;

public class Student {
    private static int nextId = 1;//用于自增
    private int id;
    private String name;
    private String major;
    private int classes;
    private int age;
    private String describe;
    private int codeNum;

    public Student(String name, String major, int classes, int age, String describe, int codeNum) {
        this.id = nextId++;
        this.name = name;
        this.major = major;
        this.classes = classes;
        this.age = age;
        this.describe = describe;
        this.codeNum = codeNum;
    }

    public static int getNextId() {
        return nextId;
    }

    public int getId() {
        return id;
    }

    public String getName() {
        return name;
    }

    public String getMajor() {
        return major;
    }

    public int getClasses() {
        return classes;
    }

    public int getAge() {
        return age;
    }

    public String getDescribe() {
        return describe;
    }

    public int getCodeNum() {
        return codeNum;
    }

    // 新增小组成员
    public static LinkedList add(LinkedList list) {
        Scanner sc = new Scanner(System.in);
        System.out.println("输入姓名：");
        String name = sc.nextLine();
        System.out.println("请输入专业：");
        String major = sc.nextLine();
        System.out.println("请输入对他的描述：");
        String describe = sc.nextLine();
        System.out.println("请输入班级：");
        int classes = sc.nextInt();
        System.out.println("请输入年龄：");
        int age = sc.nextInt();
        System.out.println("请输入代码量：");
        int codeNum=sc.nextInt();

        boolean isRepeat = false;  // 检查学生姓名是否重复

        for (int i = 0; i < list.size(); i++) {
            Student student = (Student) list.get(i);
            if (student.getName().equals(name)) {
                isRepeat = true;
                break;
            }
        }

        if (isRepeat) {
            System.out.println("插入失败，学生姓名重复：" + name);
        } else {
            list.add(new Student(name, major, classes, age, describe,codeNum));
            System.out.println("插入成功");
        }
        return list;
    }


    @Override
    public String toString() {
        return "Student{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", major='" + major + '\'' +
                ", classes=" + classes +
                ", age=" + age +
                ", describe='" + describe + '\'' +
                ", codeNum=" + codeNum +
                '}';
    }
}
